<?php
/**
 +------------------------------------------------------------------------------
 * ephpExeption异常处理
 +------------------------------------------------------------------------------
 * @Version   1.2
 * @Author    WangXian
 * @E-mail     admin@loopx.cn
 * @package  ephp
 * @FileName ephpexception.class.php
 * @Creation date 2010-10-12
 * @Modified date 2010-10-12
 +------------------------------------------------------------------------------
 */
class ephpException extends Exception
{

	public function __construct($message, $code=0, $previous=null)
	{
		//5.3.0  The previous parameter was added.
		//5.3.0 以后previous才新增的
		parent::__construct($message,$code);

		$this->ephpTraceString = $this->getTraceAsString();
		if(is_object($previous))
		{
			$this->file = $previous->getFile();
			$this->line = $previous->getLine();
			$this->ephpTraceString = $previous->getTraceAsString();
		}
	}

	/** 重载Exception的__toString()方法 **/
	public function __toString()
	{
		//是否打印异常信息
		if(! C('exception_print') ) return '';

		//是否记录异常log
		if(C('exception_log'))
		{
			$str = "\n异常信息:{$this->getMessage()}\n错误文件:{$this->getFile()}\n错误行数:{$this->getLine()}\n异常代码:{$this->getCode()}\n------------------------------";
			wlog('ExceptionLog-'.date('Y-m-d').'.log', '['. date('H:i:s') .']'.$str);
		}

		ob_start();
		include FW_PATH . '/exception/ephpexception.tpl.php';
	    return ob_get_clean();
	}

}

/* End of file ephpexception.class.php */
/* Location: ephpexception.class.php */
